Create the temporary buffer to the size of the interesction of the
authorFederico Mena Quintero <federico@redhat.com>
Wed, 24 Nov 1999 08:19:58 +0000 (08:19 +0000)
committerArturo Espinosa <unammx@src.gnome.org>
Wed, 24 Nov 1999 08:19:58 +0000 (08:19 +0000)
1999-11-22  Federico Mena Quintero  <federico@redhat.com>

* src/gnome-canvas-pixbuf.c (gnome_canvas_pixbuf_draw): Create the
temporary buffer to the size of the interesction of the bounding
box and the expose area, not the whole expose area.  This speeds
up things a lot.

* src/gdk-pixbuf-render.c (gdk_pixbuf_render_threshold_alpha): Do
not paint black on the mask, since we already cleared it in a
single gdk_draw_rectangle() operation.

gdk-pixbuf/ChangeLog
gdk-pixbuf/gnome-canvas-pixbuf.c
gdk/gdkpixbuf-render.c

index e4f332190f3ffb768cde5f04b95484ba0526c5ce..047a4e470682c5fc6d96f6bab035d896bb899977 100644 (file)
@@ -3,6 +3,17 @@
        * Removed #PRAGMA } from headers.  Also, make compile if you don't
        have it installed, already.
 
+1999-11-22  Federico Mena Quintero  <federico@redhat.com>
+
+       * src/gnome-canvas-pixbuf.c (gnome_canvas_pixbuf_draw): Create the
+       temporary buffer to the size of the interesction of the bounding
+       box and the expose area, not the whole expose area.  This speeds
+       up things a lot.
+
+       * src/gdk-pixbuf-render.c (gdk_pixbuf_render_threshold_alpha): Do
+       not paint black on the mask, since we already cleared it in a
+       single gdk_draw_rectangle() operation.
+
 1999-11-22  Raja R Harinath  <harinath@cs.umn.edu>
 
        * configure.in (GDK_PIXBUF_DIR): Fix for srcdir != builddir.
index b928e430c7b02fae10d26ef508848f620fff9bee..eef8eb12f66921408f5881a3a2aa8121878b617f 100644 (file)
@@ -552,14 +552,14 @@ compute_viewport_affine (GnomeCanvasPixbuf *gcp, double *viewport_affine, double
 
 /* Computes the affine transformation with which the pixbuf needs to be
  * transformed to render it on the canvas.  This is not the same as the
- * item_to_canvas transformation because we may need to scale the pixbuf 
+ * item_to_canvas transformation because we may need to scale the pixbuf
  * by some other amount.
  */
 static void
 compute_render_affine (GnomeCanvasPixbuf *gcp, double *render_affine, double *i2c)
 {
        double viewport_affine[6];
-       
+
        compute_viewport_affine (gcp, viewport_affine, i2c);
        art_affine_multiply (render_affine, viewport_affine, i2c);
 }
@@ -703,6 +703,8 @@ gnome_canvas_pixbuf_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
        double i2c[6], render_affine[6];
        guchar *buf;
        GdkPixbuf *pixbuf;
+       ArtIRect p_rect, a_rect, d_rect;
+       int w, h;
 
        gcp = GNOME_CANVAS_PIXBUF (item);
        priv = gcp->priv;
@@ -713,21 +715,44 @@ gnome_canvas_pixbuf_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
        gnome_canvas_item_i2c_affine (item, i2c);
        compute_render_affine (gcp, render_affine, i2c);
 
-       buf = g_new0 (guchar, width * height * 4);
-       transform_pixbuf (buf, x, y, width, height, width * 4, priv->pixbuf, render_affine);
+       /* Compute the area we need to repaint */
+
+       p_rect.x0 = item->x1;
+       p_rect.y0 = item->y1;
+       p_rect.x1 = item->x2;
+       p_rect.y1 = item->y2;
+
+       a_rect.x0 = x;
+       a_rect.y0 = y;
+       a_rect.x1 = x + width;
+       a_rect.y1 = y + height;
+
+       art_irect_intersect (&d_rect, &p_rect, &a_rect);
+       if (art_irect_empty (&d_rect))
+               return;
+
+       /* Create a temporary buffer and transform the pixbuf there */
+
+       w = d_rect.x1 - d_rect.x0;
+       h = d_rect.y1 - d_rect.y0;
+
+       buf = g_new0 (guchar, w * h * 4);
+       transform_pixbuf (buf,
+                         d_rect.x0, d_rect.y0,
+                         w, h,
+                         w * 4,
+                         priv->pixbuf, render_affine);
 
-       pixbuf = gdk_pixbuf_new_from_data (buf, ART_PIX_RGB, TRUE,
-                                          width, height, width * 4,
-                                          NULL, NULL);
+       pixbuf = gdk_pixbuf_new_from_data (buf, ART_PIX_RGB, TRUE, w, h, w * 4, NULL, NULL);
 
        gdk_pixbuf_render_to_drawable_alpha (pixbuf, drawable,
                                             0, 0,
-                                            0, 0,
-                                            width, height,
+                                            d_rect.x0 - x, d_rect.y0 - y,
+                                            w, h,
                                             GDK_PIXBUF_ALPHA_BILEVEL,
                                             128,
                                             GDK_RGB_DITHER_MAX,
-                                            x, y);
+                                            d_rect.x0, d_rect.y0);
 
        gdk_pixbuf_unref (pixbuf);
        g_free (buf);
@@ -837,7 +862,7 @@ gnome_canvas_pixbuf_bounds (GnomeCanvasItem *item, double *x1, double *y1, doubl
 
        rect.y0 = 0.0;
        rect.y1 = priv->pixbuf->art_pixbuf->height;
-       
+
        gnome_canvas_item_i2c_affine (item, i2c);
        compute_viewport_affine (gcp, viewport_affine, i2c);
        art_drect_affine_transform (&rect, &rect, viewport_affine);
index 0cc62a4bc22eb0dd478befbee746c38928aea3aa..60ee06d29f74fe6400ca9c7475a280bebe7577c1 100644 (file)
@@ -87,6 +87,9 @@ gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf, GdkBitmap *bitmap,
        gdk_gc_set_foreground (gc, &color);
        gdk_draw_rectangle (bitmap, gc, TRUE, dest_x, dest_y, width, height);
 
+       color.pixel = 1;
+       gdk_gc_set_foreground (gc, &color);
+
        for (y = 0; y < height; y++) {
                p = (apb->pixels + (y + src_y) * apb->rowstride + src_x * apb->n_channels
                     + apb->n_channels - 1);
@@ -98,11 +101,10 @@ gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf, GdkBitmap *bitmap,
                        status = *p < alpha_threshold;
 
                        if (status != start_status) {
-                               color.pixel = start_status ? 0 : 1;
-                               gdk_gc_set_foreground (gc, &color);
-                               gdk_draw_line (bitmap, gc,
-                                              start + dest_x, y + dest_y,
-                                              x - 1 + dest_x, y + dest_y);
+                               if (!start_status)
+                                       gdk_draw_line (bitmap, gc,
+                                                      start + dest_x, y + dest_y,
+                                                      x - 1 + dest_x, y + dest_y);
 
                                start = x;
                                start_status = status;
@@ -111,11 +113,10 @@ gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf, GdkBitmap *bitmap,
                        p += apb->n_channels;
                }
 
-               color.pixel = start_status ? 0 : 1;
-               gdk_gc_set_foreground (gc, &color);
-               gdk_draw_line (bitmap, gc,
-                              start + dest_x, y + dest_y,
-                              x - 1 + dest_x, y + dest_y);
+               if (!start_status)
+                       gdk_draw_line (bitmap, gc,
+                                      start + dest_x, y + dest_y,
+                                      x - 1 + dest_x, y + dest_y);
        }
 
        gdk_gc_unref (gc);